<?php
use yii\helpers\Html;
use yii\helpers\Url;
?>
<script src="/js/plugins/Highcharts-5.0.14/highcharts.js"></script>
<script src="/js/plugins/Highcharts-5.0.14/modules/exporting.js"></script>
<script src="/js/plugins/Highcharts-5.0.14/highcharts-zh_CN.js"></script>
<script src="/js/plugins/layer/laydate5.0.7/laydate.js" type="text/javascript"></script>
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>代理商 - 注册用户统计</h5>
                </div>
                <div class="ibox-content">
                    <div class="form-group form-horizontal form-style">
                        <form action="">
                            <div class="row m-b">
                                <label class="col-sm-1 control-label">代理商ID</label>
                                <div class="col-sm-2">
                                    <input type="text" readonly name="agent_id" class="form-control search_agent" value="<?=$agent_id?>" />
                                </div>
                                <label class="col-sm-1 control-label">地区</label>
                                <div class="col-sm-2 select_area form-inline">
                                    <select class="form-control" name="country_id">
                                        <option value="">全部</option>
                                        <?php if(!empty($area_list)) foreach($area_list as $key => $val){ ?>
                                            <option value="<?=$key?>" <?=$country_id == $key ? 'selected':''?> ><?=$val?></option>
                                        <?php }?>
                                    </select>
                                </div>
                                <label class="col-sm-1 control-label">日期范围</label>
                                <div class="col-xs-2">
                                    <input type="text" name="input_date" value="<?=$input_date?>" class="form-control" placeholder="选择日期">
                                </div>
                                <div class="col-sm-1">
                                    <button type="submit" class="btn btn-primary">搜索</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div id="container" style="min-width:400px;height:400px"></div>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        var categories=[
            [<?=!empty($list_user['times'])?$list_user['times']:''?>],
            [<?=!empty($list_teacher['times'])?$list_teacher['times']:''?>],
        ];
        var chart = Highcharts.chart('container',{
            chart: {
                type: 'line'
            },
            title: {
                text: '代理商：新增注册数趋势图'
            },
            subtitle: {
                text: '数据来源: 口袋鼠'
            },
            xAxis: {
                categories: categories[0]
            },
            yAxis: {
                title: {
                    text: '数值'
                }
            },
            plotOptions: {
                line: {
                    dataLabels: {
                        enabled: true          // 开启数据标签
                    },
                    enableMouseTracking: true // 关闭鼠标跟踪，对应的提示框、点击事件会失效
                },
                series: {
                    events: {
                        legendItemClick: function (e) {
                            //切换
                            for(var j=0;j<chart.series.length;j++){
                                chart.series[j].setVisible(e.target.index == j ? true : false);
                            }
                            chart.xAxis[0].update({
                                categories: categories[e.target.index]
                            });
                            return false;
                        }
                    }
                }
            },
            scrollbar: {
                enabled: true
            },
            series: [{
                name: '新增注册用户数',
                data: [<?=!empty($list_user['total_num'])?$list_user['total_num']:''?>]
            },{
                visible:false,
                name: '新增注册老师数',
                data: [<?=!empty($list_teacher['total_num'])?$list_teacher['total_num']:''?>]
            }]
        });
        $(function () {
            laydate.render({
                elem: 'input[name="input_date"]'
                ,range: '~'
                ,max: "<?=date('Y-m-d',time()-86400)?>"
                ,btns: ['confirm']
            });
            $('.search_agent').change(function(){
                var agent_id = $(this).val();
                $('select[name=country_id]').find('option:gt(0)').remove();
                if(agent_id == ''){
                    return ;
                }
                $.post('/site/get-agent-area',{'agent_id':agent_id},function(res){console.log(res.data)
                    if(res.code == 20000 ){
                        $.each(res.data,function(i,n){
                            $('select[name=country_id]').append('<option value="'+i+'">'+n+'</option>');
                        });
                    }
                },'json');
            });
        });
    </script>